#include "../src/Widget/mainwindow.h"
#include "../src/Widget/loginwidget.h"
#include "../src/CheckTool/maintool.h"
#include "../src/CheckInfor/DataBase/databasetool.h"
#include <QApplication>
#include <QTextStream>
#include <iostream>
#include <QString>
#include <QScreen>
#include <QDesktopWidget>
#include <QTextBlock>

//新终端打开
#define INSTALLMODCMD "deepin-terminal -e 'bash ../install_mods.sh %1'"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    qRegisterMetaType<Yzty::ToolCode>("ToolCode");
    qRegisterMetaType<Yzty::MODECODE>("MODECODE");
    qRegisterMetaType<Yzty::ITEMCODE>("ITEMCODE");
    qRegisterMetaType<Qt::Orientation>("Orientation");
    qRegisterMetaType<QTextBlock>("QTextBlock");
    system(QString(INSTALLMODCMD).arg("installocr").toLocal8Bit()); //检测ocr
    system(QString(INSTALLMODCMD).arg("htmltopdf").toLocal8Bit());//检测htmltopdf

    //初始化数据
    Yzty::DataBaseTool::GetInsatnce();      //启动数据库
    QDesktopWidget* dwidget=QApplication::desktop();

    LoginWidget login;
    login.show();
    MainWindow w;
    w.hide();

    // int golden = 6/10;
    // int engolden = 2/10;


    w.resize(dwidget->width()*6/10,dwidget->height()*6/10);         //useless   ?.
    w.move(dwidget->width()*2/10,dwidget->height()*2/10);           //useless   ?.

    login.resize(dwidget->width()*2/5,dwidget->height()*4/9);
    login.move(dwidget->width()*3/2/5,dwidget->height()*5/2/9);


    a.connect(&login,&LoginWidget::LoginFinish_1,[&](){
        std::cout << std::endl << "开始硬件检查..." << std::endl;
        w.CheckButton_CLick((int)Yzty::ToolCode::Hard);
    });

    a.connect(&login,&LoginWidget::LoginFinish,[&](){
        login.close();
        login.hide();
//      w.LoadConfig();
//        w.resize(dwidget->width()*golden,dwidget->height()*golden);
//        w.move(dwidget->width()*engolden,dwidget->height()*engolden);
        w.show();

    });
    a.connect(&login, &LoginWidget::LoginError,[&](){
        login.close();
    });

    a.connect(&login,&LoginWidget::LoginFault,[&](){
       login.close();
       w.close();
       login.hide();
    });
    return a.exec();
}
